import pytest
import logging
import requests


class Test():
    id = ""
    sid = ""
    uid = ""

    def setup_movie(self):
        logging.info("开始执行")
        print("准备执行用例")


    def teardown_movie(self):
        logging.info("准备执行")
        print("结束用例")


    def test_login(self):
        try:
            url = "http://10.59.9.18/movieApi/user/v2/login"
            data = {"email":"1478997572@qq.com","pwd":"eWLPHopE945d2ivttHaQTQ=="}
            re = requests.post(url=url,data=data)
            Test.uid= re.json()['result']['userId']
            Test.sid= re.json()['result']['sessionId']
            print(re.json())
        except Exception as e:
            print(e)
        assert "你的益达" in re.text

    def test_findReleaseMovieList(self):
        try:
            url = "http://10.59.9.18/movieApi/movie/v2/findReleaseMovieList"
            data = {"page":"1","count":"10"}
            re = requests.get(url=url,params=data)
            print(re.json())
        except Exception as e:
            assert "李海龙" in re.text


    def test_findNearbyCinemas(self):
        try:
            url = "http://10.59.9.18/movieApi/cinema/v1/findNearbyCinemas"
            data = {"longitude":116,"latitude":40,"page":1,"count":10}
            tou = {"userId":str(Test.uid),"sessionId":Test.sid}
            re =requests.get(url=url,headers=tou,params=data)
            assert re.json()['result'][0]['address']=='远大路1号B座5层魔影国际影城'
            print(re.json())
        except Exception as e:
            print(e)


    def test_findMovieSchedule(self):
        try:
            url = "http://10.59.9.18/movieApi/movie/v2/findMovieSchedule"
            tou = {"movieId":str(Test.uid),"cinemaId":Test.sid}
            re =requests.get(url=url,headers=tou)
            print(re.json())
            Test.id = re.json()['result'][0][id]
        except Exception as e:
            print(e)
        assert "400" in re.text

    def test_buyMovieTickets(self):
        try:
            url = "http://10.59.9.18/movieApi/movie/v2/verify/buyMovieTickets"
            tou = {"userId":str(Test.uid),"sessionId":Test.sid}
            data = {"scheduleId":Test.id,"seat":["3-7","3-8"],"sign":"6b455d84c78a5ed314e1dbcaca624636"}
            re = requests.post(url=url,json=data,headers=tou)
            print(re.json())
        except Exception as e:
            print(e)
